package com.project.work.service.impl;

import java.util.List;

import cn.hutool.core.util.IdUtil;
import com.project.common.utils.DateUtils;
import com.project.common.utils.uuid.IdUtils;
import com.project.work.domain.Enum.WorkOrderType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.project.work.mapper.BasicWorkOrderMapper;
import com.project.work.domain.BasicWorkOrder;
import com.project.work.service.IBasicWorkOrderService;

/**
 * 基础—工单Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-05
 */
@Service
public class BasicWorkOrderServiceImpl implements IBasicWorkOrderService 
{
    @Autowired
    private BasicWorkOrderMapper basicWorkOrderMapper;

    /**
     * 查询基础—工单
     * 
     * @param id 基础—工单主键
     * @return 基础—工单
     */
    @Override
    public BasicWorkOrder selectBasicWorkOrderById(Long id)
    {
        return basicWorkOrderMapper.selectBasicWorkOrderById(id);
    }

    /**
     * 查询基础—工单列表
     * 
     * @param basicWorkOrder 基础—工单
     * @return 基础—工单
     */
    @Override
    public List<BasicWorkOrder> selectBasicWorkOrderList(BasicWorkOrder basicWorkOrder)
    {
        return basicWorkOrderMapper.selectBasicWorkOrderList(basicWorkOrder);
    }

    /**
     * 新增基础—工单
     * 
     * @param basicWorkOrder 基础—工单
     * @return 结果
     */
    @Override
    public int insertBasicWorkOrder(BasicWorkOrder basicWorkOrder)
    {
        basicWorkOrder.setCreateTime(DateUtils.getNowDate());
        basicWorkOrder.setId(IdUtil.getSnowflakeNextId());
        if(basicWorkOrder.getWorkType().equals(WorkOrderType.COMPLAIN.getValue())){
            basicWorkOrder.setNumber("CO"+IdUtil.getSnowflakeNextId());
        }else if(basicWorkOrder.getWorkType().equals(WorkOrderType.REPAIR.getValue())){
            basicWorkOrder.setNumber("RE"+IdUtil.getSnowflakeNextId());
        }
        basicWorkOrder.setStatus("0");
        return basicWorkOrderMapper.insertBasicWorkOrder(basicWorkOrder);
    }

    /**
     * 修改基础—工单
     * 
     * @param basicWorkOrder 基础—工单
     * @return 结果
     */
    @Override
    public int updateBasicWorkOrder(BasicWorkOrder basicWorkOrder)
    {
        basicWorkOrder.setUpdateTime(DateUtils.getNowDate());
        return basicWorkOrderMapper.updateBasicWorkOrder(basicWorkOrder);
    }

    /**
     * 批量删除基础—工单
     * 
     * @param ids 需要删除的基础—工单主键
     * @return 结果
     */
    @Override
    public int deleteBasicWorkOrderByIds(Long[] ids)
    {
        return basicWorkOrderMapper.deleteBasicWorkOrderByIds(ids);
    }

    /**
     * 删除基础—工单信息
     * 
     * @param id 基础—工单主键
     * @return 结果
     */
    @Override
    public int deleteBasicWorkOrderById(Long id)
    {
        return basicWorkOrderMapper.deleteBasicWorkOrderById(id);
    }
}
